package com.supersit.greensproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.supersit.greensproject.R;
import com.supersit.greensproject.entity.Coordinate;

import java.util.List;

/**
 * Created by cong on 2016/7/23.
 */
public class CoordinateListAdapter extends BaseAdapter {
    private Context context;
    private List<Coordinate> list;

    public CoordinateListAdapter(Context context, List<Coordinate> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list || 0 == list.size() ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return null == list || 0 == list.size() ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder hodler;
        if (null == convertView) {
            hodler = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_coordinate_list, null);
            hodler.tvLonginude = (TextView) convertView.findViewById(R.id.tv_item_longinude);
            hodler.tvLatitude = (TextView) convertView.findViewById(R.id.tv_item_latitude);
            convertView.setTag(hodler);

        } else {
            hodler = (ViewHolder) convertView.getTag();
        }
        hodler.tvLatitude.setText("纬度：" + list.get(position).getLatitude());
        hodler.tvLonginude.setText("经度：" + list.get(position).getLongitude());

        return convertView;
    }

    class ViewHolder {
        TextView tvLatitude;
        TextView tvLonginude;
    }

    public void setData(List<Coordinate> data) {
        this.list = data;
    }
}
